<?php 
/*
 module:		基本配置控制器
 create_time:	2024-06-27 20:45:51
 author:		your name
 contact:		your email address
*/

namespace app\admin\controller\Admin;
use think\exception\ValidateException;
use app\admin\model\Admin\Config as ConfigModel;
use app\admin\controller\Admin;
use think\facade\Db;

class Config extends Admin {


	/*
 	* @Description  基本配置
 	*/
	public function index(): \think\response\Json 
	{
		$data = $this->request->post();
		$this->validate($data,\app\admin\validate\Admin\Config::class);
		$info = ConfigModel::column('data','name');
		try{
			foreach ($data as $key => $value) {
				if(array_key_exists($key,$info)){
					$config = ConfigModel::where(['name' => $key])->find()->toArray();
					if($config['data'] !== $value){
						$config['data'] = $value;
						ConfigModel::update($config);
					}
				}else{
					ConfigModel::create(['name'=>$key,'data'=>$value]);
				}
			}
		} catch (\Exception $e){
			throw new ValidateException($e->getMessage());
		}
		return json(['status'=>200]);
	}


	/*
 	* @Description  修改信息之前查询信息的 勿要删除
 	*/
	function getInfo(){
		$res = ConfigModel::column('data','name');
		return json(['status'=>200,'data'=>$res]);
	}


	/*
 	* @Description  获取定义sql语句的字段信息
 	*/
	public function getFieldList(): \think\response\Json 
	{
		return json(['status'=>200,'data'=>$this->getSqlField('',)]);
	}

	/*
 	* @Description  获取定义sql语句的字段信息
 	*/
	private function getSqlField($list): array 
	{
		$data = [];
		return $data;
	}


	

}

